<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
    
<?php
    
     $conn=@mysql_connect("localhost","root","")  or die(mysql_error());
     mysql_query("SET NAMES UTF8");
     @mysql_select_db('guyueyan',$conn) or die(mysql_error());
    
    $user_id = isset($_GET['user_id'])?  $_GET['user_id']:"";
    
    $i=0;   $k=0;
    while($k==0)   //是否点击了提交按钮
        if(isset($_POST['xiu'.$i++])){
            $k=1;
            break;
        }else if($i>=100){
            break;
        }
    $j=0;
    if($k==0){     //没有点击任何提交，那么是否点击了删除按钮
        while(true)
        if(isset($_POST['shan'.$j++])){
            $k=2;
            break;
        }else if($j>=100){
            break;
        }
    }
    if($k==0){
        echo "<script>alert('发生错误!');history.back();</script>";
        exit();
    }
    
   if($k==1){
       $i -= 2;      //因为上一个页面中count从1开始。找到那个上传按钮被点击 ann$i
       $id = $_POST['ids'][$i];
        $name = $_POST['name'][$i];
       $update = "UPDATE pictures SET name='$name' WHERE id =$id"; 
        if(mysql_query($update)){
            echo "<script>alert('修改成功!');history.back();</script>";
           
        }else{
            echo "<script>alert('修改失败!');history.back();</script>";
        }
   }else if($k==2){
       $j -= 2;
       $id = $_POST['ids'][$j];
        $name = $_POST['name'][$j];
       $delete = "DELETE FROM pictures WHERE id=$id";
       if(mysql_query($delete)){
            echo "<script>alert('删除成功!');history.back();</script>";
           /* Header("Location:/testing/pages/photo_bianji.php?id=$user_id");*/
        }else{
            echo "<script>alert('删除失败!');history.back();</script>";
        }
   }
     
    ?>
    
    
</body>
</html>